﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class DimStatement : Statement
{
    private readonly SyntaxList<VariableDeclaration> _declarations;

    private readonly SyntaxToken _dimKeywordToken;

    internal DimStatement(SyntaxToken dimKeywordToken, SyntaxNode? parent) :
        base(SyntaxKinds.DimStatement, parent)
    {
        SetChildField(ref _dimKeywordToken, dimKeywordToken);
        _declarations = new SyntaxList<VariableDeclaration>();
    }


    /// <summary>
    ///     Dim 关键字
    /// </summary>
    public SyntaxToken DimKeywordToken => _dimKeywordToken;


    /// <summary>
    ///     语句中已有的声明列表
    /// </summary>
    public IReadOnlyList<VariableDeclaration> Declarations => _declarations;


    /// <summary>
    ///     向集合末尾添加一个新的变量声明
    /// </summary>
    public void AddDeclaration(VariableDeclaration declaration)
    {
        AddChildMemberToReadOnlyField(_declarations, declaration);
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DimKeywordToken);
        AcceptList(visitor, _declarations);
    }
}


public static partial class NodeFactory
{
    public static DimStatement CreateDimStatement(SyntaxNode? parent, SyntaxToken dimKeywordToken)
    {
        Debug.Assert(dimKeywordToken.IsNode(SyntaxKinds.DimKeywordToken));
        return new DimStatement(dimKeywordToken, parent);
    }
}